<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>我的订单</title>

		<link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="../css/own.css" />

	</head>

	<body>

		<div class="mui-content mui-scroll-wrapper own-content-padding" id="completeOrder">

			<div class="mui-scroll" style="top: 48px;">
				<ul class="mui-table-view mui-table-view-chevron" id="order">

				</ul>
			</div>

		</div>
		<script type="text/javascript" src="../js/jquery-1.11.1.min.js"></script>
		<script type="text/javascript" src="../js/jquery-1.11.1.min.js"></script>
		<script src="../js/mui.min.js" charset="UTF-8"></script>
		<script src="../js/own.js" charset="UTF-8"></script>
		<script type="text/javascript" charset="UTF-8">
			mui.plusReady(function() {

			

				window.addEventListener('refresh', function() {
					//alert(555);
					plus.webview.currentWebview().reload();
				});

				var data = {};
				data.accountId = plus.storage.getItem("accountId");
				data.tokenCode = plus.storage.getItem("tokenCode");
				//alert(data.accountId)
				//alert(data.tokenCode)
				data.serviceType = '0'; //0：被服务方,1：服务方（两个客户端参数约定）
				data.offset = 0; //从哪一条记录开始
				data.limit = 50; //每一页多少条记录
				$.ajax({
					url: url + 'rest/myOrder',
					type: "POST",
					data: data,
					success: function(result) {
						//返回json字符串，转成json对象进行属性获取

						result = JSON.parse(result);
						$("#resultCode").val(result.status);
						$("#resultMsg").val(result.msg);
						if(result.status != '0') {
							alert(result.msg);
						} else {

							var dataTable = result.data;
							//var table = $("#completeOrder");
							//table.empty();
							var tableStr = "";
							//tableStr += '<div class="mui-content own-content-padding">';

							//tableStr += "<thead><th>商品名称</th><th>商品数量</th><th>商品价格</th><th>联系方式</th><th>收货人</th><th>收货地址</th><th>状态</th><th>操作</th></thead>";
							tableStr += '<ul  class="mui-table-view">';

							for(var i = 0; i < dataTable.length; i++) {

								var status;

								if(dataTable[i].paystatus == 'n' && dataTable[i].status != '已取消') {
									status = '待支付';
								} else {
									status = dataTable[i].status;
								}
								//alert(dataTable[i].shipname);
								tableStr += '<li class="mui-table-view-cell">';
								tableStr += '<div class="mui-row" style="margin-top: 5px;">';

								tableStr += '<span class="mui-col-xs-4 serviceDate">' + dataTable[i].serviceDate + '</span>';
								tableStr += '<span class="mui-col-xs-5 productName" style="color: #04BB21;">' + dataTable[i].productName + '</span>';
								tableStr += '<span class="mui-col-xs-2 status">' + status + '</span>';

								tableStr += '</div>';
								tableStr += '<div class="mui-row" style="margin-top: 5px;">';
								tableStr += '<span class="mui-col-xs-1 mui-icon mui-icon-person"></span>';
								tableStr += '<span class="mui-col-xs-3 shipname">';
								tableStr += dataTable[i].shipname;
								tableStr += '</span>';
								tableStr += '<span class="mui-col-xs-6 mui-icon mui-icon-phone Phone" style="font-size:16px">' + dataTable[i].phone + '</span>';
								tableStr += '<span class="mui-col-xs-2 mui-icon mui-icon-arrowright"></span>';
								tableStr += '</div>';
								tableStr += '<div class="mui-row" style="margin-top: 5px;">';
								tableStr += '<span class="mui-col-xs-1 mui-icon mui-icon-location" ></span>';
								tableStr += '<span class="shipaddress">' + dataTable[i].province + " " + dataTable[i].city + " " + dataTable[i].area + " " + dataTable[i].shipaddress + '</span>';
								tableStr += '<p class="orderId" hidden>' + dataTable[i].orderId + '</p>';
								tableStr += '<p class="number" hidden>' + dataTable[i].number + '</p>';
								tableStr += '<p class="productId" hidden>' + dataTable[i].prodcutId + '</p>';
								tableStr += '<p class="pTotal" hidden>' + dataTable[i].pTotal + '</p>';
								tableStr += '<p class="amount" hidden>' + dataTable[i].amount + '</p>';
								tableStr += '<p class="publicMoney" hidden>' + dataTable[i].publicMoney + '</p>';
								tableStr += '<p class="detailId" hidden>' + dataTable[i].detailId + '</p>';
								tableStr += '</div>';

								tableStr += '</li>';
							}
							tableStr += '</ul>';
							if(dataTable.length == 0) {
								tableStr += "<div class='own-left-nav-color' style = 'text-align: center;margin-top: 50px;font-size: 0.9em;'>";
								tableStr += "<span>空空如也</span>";
								tableStr += "<br />";
								tableStr += "<span>你还没有下过订单哦</span>";
								tableStr += "<br />";
								tableStr += "</div>";
							}
							//tableStr +='</div>';
							//table.append(tableStr);
							document.getElementById("completeOrder").innerHTML = tableStr;

							mui('.mui-table-view').on('tap', '.mui-table-view-cell', function() {
								//var cell = this;
								//alert(11);
								data.serviceDate = $(this).children().children(".serviceDate").text();
								data.productName = $(this).children().children(".productName").text();
								data.servicePerson = $(this).children().children(".shipname").text();
								data.servicePersonPhone = $(this).children().children(".Phone").text();
								data.shipAddress = $(this).children().children(".shipaddress").text().split(" ")[3];
								data.orderId = $(this).children().children(".orderId").text();
								data.status = $(this).children().children(".status").text();

								data.numbers = $(this).children().children(".numbers").text();

								data.productId = $(this).children().children(".productId").text();
								data.amount = $(this).children().children(".amount").text();
								data.pTotal = $(this).children().children(".pTotal").text();
								data.province = $(this).children().children(".shipaddress").text().split(" ")[0];
								data.city = $(this).children().children(".shipaddress").text().split(" ")[1];
								data.area = $(this).children().children(".shipaddress").text().split(" ")[2];
								data.publicMoney = $(this).children().children(".publicMoney").text();
								data.detailId = $(this).children().children(".detailId").text();
								data.productId = $(this).children().children(".productId").text();

								var dataStr = JSON.stringify(data);

								mui.openWindow({
									url: 'myOrder.html',
									id: 'myOrder.html',
									extras: {
										dataStr: dataStr
									}
								});

							});

						}
					}
				});

			});
		</script>

	</body>

</html>